<?php
require_once('../../../../conf/config.php.inc');
require_once(SYBMAS_LIB_PATH.'/liblogin.php.inc');
require_once(SYBMAS_LAYOUT_PATH.'/layout.php.inc');
require_once(SYBMAS_LIB_PATH.'/libsybmas.php.inc');
require_once(SYBMAS_LAYOUT_PATH.'/menu.php.inc');
require_once('../../lib/libtablas.php.inc');
verificar_inicio_sesion();
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css"
	href="<?php echo LAYOUT_URI?>/sybmasstyle.css">
<script src="<?php echo LAYOUT_URI?>/jquery-1.2.1.min.js"
	type="text/javascript"></script>
<script src="<?php echo LAYOUT_URI?>/menu-collapsed.js"
	type="text/javascript"></script>
<link rel="stylesheet" type="text/css"
	href="<?php echo LAYOUT_URI?>/style.css" >
<link rel="stylesheet" type="text/css"
	href="<?php echo JAVASCRIPT_URI?>/tabs/tabs.css">
<script src="<?php echo JAVASCRIPT_URI?>/tabs/tabs.js"
	type="text/javascript"></script>
<script src="<?php echo JAVASCRIPT_URI?>/validacionFormularios.js"
	type="text/javascript"></script>

<script type="text/javascript" src="<?php echo JAVASCRIPT_URI?>/commons.js">></script>
<script type="text/javascript" src="index.js"></script>
<script type="text/javascript" src="agregar.js"></script>
<script type="text/javascript" src="pkunique.js"></script>
<script type="text/javascript" src="tabla.js"></script>

<title>.:: Sybmas - Crear tabla</title>
<!--[if lt IE 8]>
   <style type="text/css">
   li a {display:inline-block;}
   li a {display:block;}
   </style>
   <![endif]-->
</head>
<body>
<script src="<?php echo JAVASCRIPT_URI?>/tooltip/wz_tooltip.js"
	type="text/javascript"></script>
<center>

<div id="container">
<div id="header"><?php generar_header();?></div>
<div id="scene">
<div id="modulos">
<ul id="menu" style="width: 150px;">
<?php generar_menu();?>
</ul>
</div>
<?php
$dbname=false;
foreach($_POST as $key=>$value){
	$$key=$value;
}

?>
<div id="title">Crear tabla</div>
<div id="main"><?php
$cambio_bd_exitoso=true;
$sybuser_connection=start_default_sybuser_connection();
if($dbname){
	$cambio_bd_exitoso=sybase_select_db($dbname,$sybuser_connection);
}

if($cambio_bd_exitoso){
?>

<h1>Proporcione los siguientes datos para crear la tabla</h1>

<form action="tabla2.php" method="post" onsubmit="return verificarFormularioCrearTabla()">
<?php if($dbname){?> 
<input
	type="hidden" name="dbname" value="<?php echo $dbname?>"> 
	<?php }?> 
<div id="tab_panel">
<div id="tab_header">
<ul>
	<li id="selected"><a id="ctl_tabgeneral" href="#" onclick="showTab(this.id,0)">Inf. basica</a></li>
	<li><a id="ctl_tabcolumnas" href="#" onclick="showTab(this.id,1)">Columnas</a></li>
	<li><a id="ctl_tabrestricciones" href="#" onclick="showTab(this.id,2)">Restricciones</a></li>	
	<li><a id="ctl_tabopciones" href="#" onclick="showTab(this.id,3)">Opciones</a></li>
</ul>
</div>
<div id="tab_content">

<div class="tab_scene" style="display: block">

<table width="80%" border="1" id="index_basic">
	<caption>Informacion b&aacute;sica</caption>
	<tr>
		<th>Nombre del tabla</th>
		<td><input type="text" id="tablename" name="tablename"
			maxlength="30" title="Nombre del &iacute;ndice" 
			onkeydown="return onKeyPressPermiteAlfaNumericosNoEspacios(event)"></td>			
	</tr>
	<tr>
		<th>Base de datos</th>
		<td>		
			<?php 
				sybase_min_server_severity(11);
				$sybmas_connection=start_sybmas_connection();

				//Se obtienen los nombres de las bases de datos disponibles
				$query="SELECT name FROM master..sysdatabases";
				$result=sybase_query($query,$sybmas_connection);
			
			?>
			<select name="dbname">
			<?php
				while($data=sybase_fetch_array($result)){
					echo '<option value="'.$data['name'].'"';
					if(empty($dbname)){
						echo $_SESSION['sybmas.user.dbname']==$data['name']?' selected ':'';
					}else{
						echo $dbname==$data['name']?' selected ':'';
					}
					echo '>'.$data['name']."</option>\n";
				}
				sybase_free_result($result);
			?>			
			</select>		
		</td>
	</tr>		
</table>
</div>
					
<div class="tab_scene">
<div class="controls">
<input type="button" value="Agregar columna" onclick="showDialog('agregar.php')">
</div>

<table border="1">
	<caption>Agregar la definicion de las columnas de la tabla</caption>
	<tbody id="tbl_columnas">
		<tr id="tbl_columnas_header">
			<th>nombre</th>
			<th>tipo</th>
			<th>longitud</th>
			<th>valor pred.</th>
			<th>nulos/identidad</th>
		</tr>		
	</tbody>
</table>
</div>



<div class="tab_scene">

<div id="controls_restricciones" class="controls">
	<input type="button" value="Agregar restriccion" onclick="showDialogConstraints(document.getElementById('tablename').value)">
	<input type="radio" name="constraintType" id="constraintTypePk" value="pk">Llave primaria
	<input type="radio" name="constraintType" value="u">De unicidad
	<input type="radio" name="constraintType" value="fk" checked="checked">Llave foranea
	<input type="radio" name="constraintType" value="c">Check	
</div>


<table width="80%" border="1">
<caption>Restricciones</caption>
<tbody id="tbl_restricciones">
	<tr id="tbl_restricciones_header">
		<th>nombre</th>
		<th>definicion</th>
	</tr>
</tbody>
</table>
</div>

<?php
$query="SELECT s.status,s.name ".
		"FROM syssegments s ".
		"WHERE s.name NOT IN ('system','logsegment')".
		"ORDER BY s.name ASC ";
$result_segmentos=sybase_query($query,$sybuser_connection);
?>

<div class="tab_scene">
<table width="80%" border="1" id="index_storage">
	<caption>Parametros de almacenamiento</caption>
	<tr>
		<th>Bloqueos</th>
		<td>
			<input type="radio" name="lock" id="lock_datarows">datarows 
			<input type="radio" name="lock" id="lock_datapages">datapages 
			<input type="radio" name="lock" id="lock_allpages">allpages
		</td>
	</tr>	
	<tr>
		<th>Filas m&aacute;ximas por p&aacute;gina</th>
		<td><input type="text" title="max_rows_per_page"
			name="max_rows_per_page" maxlength="3" onkeypress="return onKeyPressPermiteNumeros(event)" ></td>
	</tr>
	<tr>
		<th>Tama&ntilde;o esperado por fila</th>
		<td><input id="exp_row_size" type="text" title="exp_row_size"
			name="exp_row_size" maxlength="3" onkeypress="return onKeyPressPermiteNumeros(event)"></td>
	</tr>
	<tr>
		<th>Espacio reservado vac&iacute;o por p&aacute;gina</th>
		<td><input type="text" title="reservspacegap" name="reservspacegap"
			maxlength="3" onkeypress="return onKeyPressPermiteNumeros(event)"></td>
	</tr>
	<tr>
		<th>Segmento</th>
		<td><select name="segment">
		<?php while($data=sybase_fetch_array($result_segmentos)){
			?>
			<option value="<?php echo $data['name']?>"
			<?php echo $data['status']==1?' selected ':''?>><?php echo $data['name']?>			
			</option>
			<?php }?>
		</select></td>
	</tr>
</table>
</div>
<?php
sybase_free_result($result_segmentos);
?>
	
</div><!-- tab_content -->
</div><!-- tab_panel -->

<table>
	<tr>
		<td colspan="2"><input type="submit" value="Crear tabla"> <input
			type="button" value="Cancelar" onclick="history.back()" ></td>
	</tr>
</table>

</form>
<?php
}//if($cambio_bd_exitoso)

//Cerrando conexiones a la base de datos
sybase_close($sybuser_connection);
?>


</div>
<!-- main --></div>
<!-- scene --> 
<?php generar_footer();?></div>
</center>
</body>
</html>
